<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Auth;

/**
 * 套餐
 * @package App\Models
 */
class Package extends Model
{
    use HasFactory;
    protected $fillable = ['title'];

    protected $appends = ['permissions'];

    public function getPermissionsAttribute()
    {
        return [
            'delete' => Auth::check() && Auth::user()->can('delete', $this)
        ];
    }

    /**
     * 使用套餐会员组
     *
     * @return void
     */
    public function groups()
    {
        return $this->belongsToMany(Group::class, 'group_package');
    }

    public function modules()
    {
        return $this->belongsToMany(Module::class, 'module_package')->withTimestamps();
    }
}
